//
//  MenuItemComplete.m
//  cocos2dappfwk
//
//  Created by Connor on 2/28/10.
//  Copyright 2010 Lowrie Associates Ltd. All rights reserved.
//

#import "MenuItemComplete.h"

#pragma mark MenuItemComplete

enum {
	kZoomActionTag = 0xc0c05002,
};


@implementation MenuItemComplete
@synthesize sprite, spriteDisabled, title;

-(id) initFromImage:(NSString *)image title:(CCLabel *)t target:(id)target selector:(SEL)selector
{
	if( (self=[super initWithTarget:target selector:selector]) ) {
		
		originalScale_ = 1;
		
		self.sprite = [CCSprite spriteWithFile:image];
		self.spriteDisabled = [CCSprite spriteWithFile:image];
		[self.spriteDisabled setOpacity:80];
		[self setContentSize: [self.sprite contentSize]];
		
		self.title = t;
		self.title.position = ccp(self.contentSize.width/2 , -10);
		[self addChild: title z:100];
	}
	return self;	
}

-(void) draw
{
	if(isEnabled_)
		[sprite draw];				
	else
		[spriteDisabled draw];
}

-(void) dealloc
{
	[sprite release];
	[spriteDisabled release];
	[title release];
	[super dealloc];
}

-(void) activate {
	if(isEnabled_) {
		[self stopAllActions];
        
		self.scale = originalScale_;
        
		[super activate];
	}
}

-(void) selected
{
	if(isEnabled_) {	
		[super selected];
		[self stopActionByTag:kZoomActionTag];
		originalScale_ = self.scale;
		CCAction *zoomAction = [CCScaleTo actionWithDuration:0.1f scale:originalScale_ * 1.2f];
		zoomAction.tag = kZoomActionTag;
		[self runAction:zoomAction];
	}
}

-(void) unselected
{
	if(isEnabled_) {
		[super unselected];
		[self stopActionByTag:kZoomActionTag];
		CCAction *zoomAction = [CCScaleTo actionWithDuration:0.1f scale:originalScale_];
		zoomAction.tag = kZoomActionTag;
		[self runAction:zoomAction];
	}
}

- (void) setOpacity: (GLubyte)opacity
{
	[sprite setOpacity:opacity];
	[title setOpacity:opacity];
}


-(void) setColor:(ccColor3B)color
{
	[sprite setColor:color];
}


-(GLubyte) opacity
{
	return [sprite opacity];
}

-(ccColor3B) color
{
	return [sprite color];
}

#pragma mark --
@end
